<?php

Yii::import('application.models._base.BaseUser');

define("SALT_LENGTH", 10);

class User extends BaseUser
{

    public $old_password;
    public $new_password;
    public $repeat_password;

	public static function model($className=__CLASS__) {
		return parent::model($className);
	}

    /**
     * @return boolean validate user
     */
    public function validatePassword($password)
    {
        return CPasswordHelper::verifyPassword($password,$this->password);
    }
    /**
     * @return hashed value
     */


    public function hashPassword($password)
    {
        return CPasswordHelper::hashPassword($password);
    }


    //matching the old password with your existing password.
    public function findPasswords($attribute, $params)
    {
        //$user = User::model()->findByAttributes(array('id'=>Yii::app()->user->id));
        //echo Yii::app()->user->id;
        $user = User::model()->findByAttributes(array('id'=>1));
        if (!CPasswordHelper::verifyPassword($this->old_password,$user->password))
            $this->addError($attribute, 'Old password is incorrect.');
    }
}
